﻿/*

  The contents of this file are subject to the Mozilla Public License Version
  1.1 (the "License"); you may not use this file except in compliance with
  the License. You may obtain a copy of the License at 
  
           http://www.mozilla.org/MPL/ 
  
  Software distributed under the License is distributed on an "AS IS" basis,
  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  for the specific language governing rights and limitations under the License. 
  
  The Original Code is AST'r Framework.
  
  The Initial Developer of the Original Code is
  ALCARAZ Marc (aka eKameleon) <vegas@ekameleon.net>.
  Portions created by the Initial Developer are Copyright (C) 2004-2007
  the Initial Developer. All Rights Reserved.
  
  Contributor(s) :
  
 */

import asgard.display.ConfigurableDisplayObject;

import echat.application.ControllerEngine;
import echat.application.ModelEngine;
import echat.application.ViewEngine;
import echat.display.DisplayList;
import echat.process.application.RunApplication;

import mars.logging.ApplicationLogger;
import mars.ui.ApplicationContextMenu;

// TODO example in progress...

/**
 * The main class of the application.
 * @author eKameleon
 */
class echat.Application extends ConfigurableDisplayObject 
{
	
	/**
	 * Creates a new ConfigurableDisplayObject instance.
	 * @param target the DisplayObject instance control this target.
	 */
	private function Application( target:MovieClip ) 
	{
		
		super( DisplayList.APPLICATION , target ) ;
		
		// Initialize logs		
		ApplicationLogger.initialize() ;
		
		// Initialize the target of the ContextMenu of the application.
		
		ApplicationContextMenu.getInstance().addMenu( target ) ;
				
		// MVC
		
		ModelEngine.initialize() ;
		ControllerEngine.initialize() ;
		ViewEngine.initialize( this ) ;
		
		// Run the application
		
		RunApplication.getInstance().run() ;
		
	}
	
	/**
	 * The static singleton reference of this class.
	 */
	public static var application:Application ;
	
	/**
	 * The static main method of this application.
	 */
	public static function main( target:MovieClip ):Void
	{
		if (application == null)
		{
			application = new Application( target ) ;	
		}
	}

}